home *** CD-ROM | disk | FTP | other *** search
- /* BasicApp.c */
-
- #define TARGET_CARBON 1
-
- #include <Events.h> /* SystemClick */
- #include <Quickdraw.h> /* InitGraf,InitCursor */
- #include <Menus.h> /* InitMenus */
- #include <Fonts.h> /* InitFonts */
- #include <MacTypes.h> /* Rect struct typedef */
- #include <Sound.h> /* SysBeep */
- #include <SegLoad.h> /* ExitToShell */
- #include <ToolUtils.h> /* for HiWord,LoWord */
- #include <MacWindows.h>
-
- void Initialize(void); /* function prototypes */
- void EventLoop(void);
- void MakeWindow(void);
- void MakeMenu(void);
- void DoEvent(EventRecord *event);
- void DoMenuCommand(long menuResult);
- void DoAboutBox(void);
-
- #define rMenuBar 128 /* menu bar */
- #define mApple 128 /* Apple menu */
- #define iAbout 1
- #define mFile 129 /* File menu */
- #define iNew 1
- #define iClose 4
- #define iQuit 11
- #define mEdit 130 /* Edit menu */
- #define mHello 131 /* Hello menu */
- #define iThis 1
- #define iThat 2
- #define kAboutBox 200 /* Dialog resource for About box */
-
- WindowPtr myWindow; /* global */
-
- void main()
- {
- Initialize();
- MakeWindow();
- MakeMenu();
-
- EventLoop();
- }
-
- void Initialize() /* Initialize some managers */
- {
- InitCursor();
- }
-
- void EventLoop()
- {
- Boolean gotEvent;
- EventRecord event;
-
- do
- {
- gotEvent = WaitNextEvent(everyEvent,&event,0,nil);
- if (gotEvent)
- DoEvent(&event);
- } while (true); /* loop forever */
- }
-
- void MakeWindow() /* Put a window */
- {
- Rect wRect;
-
- SetRect(&wRect,50,50,600,200); /* left, top, right, bottom */
- myWindow = NewWindow(nil, &wRect, "\pHello", true, zoomNoGrow, (WindowPtr) -1, false, 0);
- if (myWindow == nil)
- {
- ExitToShell();
- }
- else
- SetPort(GetWindowPort(myWindow)); /* set port to new window */
- }
-
- void MakeMenu() /* Put up a menu */
- {
- Handle menuBar;
-
- menuBar = GetNewMBar(rMenuBar); /* read menus into menu bar */
- if ( menuBar != nil )
- {
- SetMenuBar(menuBar); /* install menus */
- // DisposHandle(menuBar);
- AppendResMenu(GetMenuHandle(mApple), 'DRVR'); /* add DA names to Apple menu */
- DrawMenuBar();
- }
- if ( menuBar == nil )
- {
- DebugStr("\pMakeMenu");
- ExitToShell();
- }
- }
-
- void DoEvent(EventRecord *event)
- {
- short part;
- Boolean hit;
- char key;
- Rect tempRect;
-
- switch (event->what)
- {
- case mouseDown:
- part = FindWindow(event->where, &myWindow);
- switch (part)
- {
- case inMenuBar: /* process a moused menu command */
- DoMenuCommand(MenuSelect(event->where));
- break;
- case inSysWindow: /* let system handle it */
- SystemClick(event, myWindow);
- break;
- case inContent:
- if (myWindow != FrontWindow())
- SelectWindow(myWindow);
- break;
- case inDrag: /* pass screenBits.bounds */
- GetRegionBounds( GetGrayRgn(), &tempRect );
- DragWindow(myWindow, event->where, &tempRect);
- break;
- case inGrow:
- break;
- case inZoomIn:
- case inZoomOut:
- hit = TrackBox(myWindow, event->where, part);
- if (hit)
- {
- SetPort(GetWindowPort(myWindow)); /* window must be current port */
- EraseRect(GetWindowPortBounds(myWindow, &tempRect)); /* b/c ZoomWindow bug */
- ZoomWindow(myWindow, part, true); /* we inval/erase to */
- InvalWindowRect(myWindow,GetWindowPortBounds(myWindow, &tempRect)); /* look better */
- }
- break;
- }
- break;
- case keyDown:
- case autoKey:
- key = event->message & charCodeMask;
- if (event->modifiers & cmdKey)
- if (event->what == keyDown)
- DoMenuCommand(MenuKey(key));
- case activateEvt: /* if you needed to do something special */
- case updateEvt:
- BeginUpdate((WindowPtr)event->message);
- EndUpdate((WindowPtr)event->message);
- case diskEvt:
- break;
- }
- }
-
- void DoMenuCommand(long menuResult)
- {
- short menuID; /* the resource ID of the selected menu */
- short menuItem; /* the item number of the selected menu */
-
- menuID = HiWord(menuResult); /* use macros to get item & menu number */
- menuItem = LoWord(menuResult);
-
- switch (menuID)
- {
- case mApple:
- switch (menuItem)
- {
- case iAbout:
- DoAboutBox();
- break;
- default:
- break;
- }
- break;
- case mFile:
- switch (menuItem)
- {
- case iQuit:
- ExitToShell();
- break;
- }
- break;
- case mEdit:
- break;
- case mHello:
- switch (menuItem)
- {
- case iThis:
- SysBeep(2);
- break;
- case iThat:
- SysBeep(2);
- break;
- }
- break;
- }
- HiliteMenu(0); /* unhighlight what MenuSelect (or MenuKey) hilited */
- }
-
- void DoAboutBox(void)
- {
- //Carbon currently has an event problem with modal dialogs
- //will put this back soon...
-
- //(void) Alert(kAboutBox, nil); // simple alert dialog box
- }